const {
  $util,
} = getApp();
Page({
  data: {
    imgs: [],
    title: '',
    content: '',
    id: '',
  },
  onLoad(opts) {
    this.setData(opts);
    opts.id && this.loadDetail();
  },
  loadDetail() {
    $util.request({
      url: 'entry/wxapp/partyman.promisenew.getPromiseDetail',
      data: {
        id: this.data.id,
      },
      success: (res) => {
        this.setData(res.data);
      },
    });
  },
  setRemark(e) {
    this.setData({
      title: e.detail.value,
    });
  },
  setContent(e) {
    this.setData({
      content: e.detail.value,
      conLen: e.detail.value.length,
    });
  },
  imgsOnChange(e) {
    this.setData({
      imgs: e.detail,
    });
  },
  raduiOnChange(e) {
    this.setData({
      flag: e.detail.value,
    });
  },
  /**
   * 提交
   */
  submit() {
    const {
      title,
      imgs,
      content,
    } = this.data;
    if (title.trim() === '') {
      wx.showModal({
        title: '提示',
        content: '承诺标题不能为空',
        showCancel: false,
      });
      return;
    }
    if (content.trim() === '') {
      wx.showModal({
        title: '提示',
        content: '承若内容不能为空',
        showCancel: false,
      });
      return;
    }
    $util.request({
      url: 'entry/wxapp/partyman.promisenew.uploadPromise',
      data: {
        title,
        content,
        picture: imgs.toString(),
      },
      success: (res) => {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          success: () => {
            setTimeout(() => {
              wx.navigateBack();
            }, 1000);
          },
        });
      },
    });
  },
});
